<template>
    <view class="w-full h-screen box-border pt-[var(--top-m)] bg-[var(--page-bg-color)] setting-wrap"
        :style="themeColor()">
        <view class="mb-[var(--top-m)] sidebar-margin card-template !py-[20rpx]">
            <u-cell-group :border="false" class="cell-group">
                <!-- <u-cell :title="t('personalSettings')" :is-link="true" url="/app/pages/member/personal"></u-cell> -->
                <u-cell :title="'切换门店'" :is-link="true" :value="tenant" @click="tenantSheetShow"></u-cell>
                <!-- #ifdef APP-PLUS -->
                <u-cell :title="t('version')" :value="version" @click="checkUpdate()"></u-cell>
                <!-- #endif -->
                <!-- #ifndef APP-PLUS -->
                <u-cell :title="t('version')" :value="version"></u-cell>
                <!-- #endif -->
            </u-cell-group>
        </view>

        <view class="mb-[var(--top-m)] sidebar-margin card-template !py-[20rpx]">
            <u-cell-group :border="false" class="cell-group">
                <u-cell :title="t('userAgreement')" :is-link="true"
                    url="/app/pages/auth/agreement?key=service"></u-cell>
                <u-cell :title="t('privacyAgreement')" :is-link="true"
                    url="/app/pages/auth/agreement?key=privacy"></u-cell>
            </u-cell-group>
        </view>

        <view class="h-[88rpx] flex-center bg-[#fff] mx-[var(--sidebar-m)] rounded-[var(--rounded-big)] text-[32rpx]"
            @click="memberStore.logout(true)">{{ t('logout') }}</view>


        <!-- 切换门店 -->
        <select-tenant ref="tenantRef" :is-radio="true" @confirm="switchTenantFn" />


    </view>
    <!-- 水印 -->
    <watermark></watermark>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onMounted, watch } from 'vue'
import useMemberStore from '@/stores/member'
import { t, language } from '@/locale'
import { getAccountBindTenantList, switchTenant } from '@/app/api/system'
import { onShow } from '@dcloudio/uni-app'
// #ifdef APP-PLUS

import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
// #endif

const memberStore = useMemberStore()

const version = ref(import.meta.env.VITE_APP_VERSION)


/**
 * 当前门店
 */
// const tenantId = ref(uni.getStorageSync('wap_tentant_id'))
// const tenant = ref(uni.getStorageSync('wap_member_tenant'))
const tenantId = computed(() => {
    return memberStore.tenantId;
})
const tenant = computed(() => {
    return memberStore.tenant;

})




/**
 * 切换门店
 * 获取门店列表
 */
const tenantRef = ref()

const tenantSheetShow = () => {
    tenantRef.value.open([{ id: tenantId.value, name: tenant.value }])
}



const switchTenantFn = (tenant: any) => {
    console.log(tenant)
    uni.removeStorageSync('wap_tentant_id')
    uni.removeStorageSync('wap_member_tenant')
    switchTenant({ tenantId: tenant[0].id }).then((res: any) => {
        memberStore.setTenantId(res.data.tenantId)

        memberStore.setToken(res.data.accessToken)




    })

}
onShow(() => {
    const baseInfo = uni.getAppBaseInfo();
    console.log(baseInfo)
    version.value = baseInfo.appVersion
})
onMounted(() => {

})
</script>

<style lang="scss" scoped>
page {
    background: var(--page-bg-color);
}

:deep(.cell-group),
:deep(.u-cell-group) {
    .u-cell {
        .u-cell__body {
            padding: 0;
            height: 90rpx;
            margin-top: 16rpx;
        }

        &:first-of-type .u-cell__body {
            margin-top: 0;
        }

        .u-cell__title-text {
            font-size: 32rpx;
            line-height: 40rpx;
        }

        .u-icon__icon {
            font-size: 24rpx !important;
        }

        .u-cell__value {
            line-height: 1;
            font-size: 32rpx;
        }

        .u-line {
            display: none;
        }
    }
}

:deep(.u-action-sheet) {
    .u-line {
        margin: 0 30rpx !important;
        width: auto !important;
        border-color: #ddd !important;
    }

    .u-action-sheet__cancel {
        padding: 0;

    }

    .u-action-sheet__item-wrap__item__name {
        font-size: 30rpx !important;
    }
}
</style>
<style>
.setting-wrap .u-cell--clickable {
    background-color: transparent !important;
}
</style>
